package com.gwu.manger.comm.aop;

import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import com.gwu.manger.comm.annotation.DataSource;
import com.gwu.manger.comm.multiple.DataSourceContextHolder;



/**
 * 
 * @author gwu
 * @version 1.0.0
 */
@Component
@Aspect
@Order(-1)
public class DataSourceAspect {
	@Pointcut("@within(com.gwu.manger.comm.annotation.DataSource)")
	public void pointCut() {

	}

	@Before("pointCut() && @annotation(dataSource)")
	public void doBefore(DataSource dataSource) {
		DataSourceContextHolder.setDataSource(dataSource.value().getValue());
	}

	@After("pointCut()")
	public void doAfter() {
		DataSourceContextHolder.clear();
	}
}
